﻿<%@ Control Language="VB" AutoEventWireup="false" CodeFile="Section02.ascx.vb" Inherits="Control_MSDS_Section02" %>
<%@ Register TagPrefix="CE" Namespace="CuteEditor" Assembly="CuteEditor" %>

<style type="text/css">
	textarea {
		height: 100%!important;
		width: 99.6%;
	}
</style>
<script type="text/javascript">
	function ajaxJquery() {
		$(function () {
			$(".TextBox:first").focus();
			$("[id*=btnAdd1]").click(function () {
				AddNewRow('', '', '', '');
			});
			if ("<%=hidMSDSID.Value%>" * 1 > 0) {
				//'' Thực hiện Ajax lấy data Detail
				$.ajax({
					url: '<%=ResolveUrl("~/Services/wsAutoComplete.asmx/GetDataSection02Detail")%>',
					data: "{ 'strSection02ID': '" + <%= hidMSDSID.Value%> + "'}",
					dataType: "json",
					type: "POST",
					contentType: "application/json; charset=utf-8",
					beforeSend: function () {
						$("#[id*=UpdateProgress1]").css({ 'display': 'block' });
					},
					success: function (data) {
						try {
							if (data.d.trim() == "") {
								$("[id*=btnAdd1]").click();
							}
							else {
								$.each(data.d.split("$"), function (idx, obj) {
									var _tempValue = obj.split("@");
									if (_tempValue.length > 3) {
										AddNewRow(_tempValue[0], _tempValue[1], _tempValue[2], _tempValue[3]);
									}
								});
							}
							$("#[id*=UpdateProgress1]").css({ 'display': 'none' });
						} catch (e) { $("#[id*=UpdateProgress1]").css({ 'display': 'none' }); }
					},
					error: function (XMLHttpRequest, textStatus, errorThrown) {
						//Alertbox(textStatus);
						$("#[id*=UpdateProgress1]").css({ 'display': 'none' });
					}
				});
			} else {
				$("[id*=btnAdd1]").click();
			}
		});
	}

	// Xoa dong
	function RemoveRow(obj) {
		$(obj).closest("tr").fadeOut(500, function () {
			$(this).remove();
		});
		return false;
	}

	function AddNewRow(_tp, _soCAS, _cthh, _hl) {
		try {
			var index = 0;
			index = Math.floor(Math.random() * 100);
			var _newCtrl = "txtCTHH" + index
			var _cuteHTML = $("#divTemplate").html().replace(/txtTemplate/gi, _newCtrl);
			var _html = "<tr  id='" + index + "' style='height:220px;' data-ctrlName='" + _newCtrl + "'>"
							+ "<td width='5%' class='text_list_links' align='center'><a  class='delbutton' style='cursor:pointer;' onclick=\"RemoveRow(this);\" > <%=hidDel.Value %> </a> </td>"
								+ "<td width='20%' class='text_list_links' align='center'>"
									+ "<textarea rows='4' id='txtThanhPhan" + index + "' class='ThanhPhan'>" + _tp + "</textarea>"
								+ "</td>"
								+ "<td width='20%' class='text_list_links' align='center'>"
									+ "<textarea rows='4' id='txtSoCAS" + index + "' class='SoCAS'>" + _soCAS + "</textarea>"
								+ "</td>"
								+ "<td width='40%' class='text_list_links' align='center' >"
									//+ "<textarea rows='4' id='txtCTHH" + index + "' class='CTHH'>" + _cthh + "</textarea>"
								+ _cuteHTML
								+ "</td>"
								+ "<td width='15%' class='text_list_links' align='center'>"
									+ "<textarea rows='4' id='txtHamLuong" + index + "' class='HamLuong'>" + _hl + "</textarea>"
								+ "</td>"
							+ "</tr>"
			$("#tb1").append(_html);
			setTimeout(function () {
				var _idCtrlEditor = '<%= txtTemplate.ClientID%>'.replace(/txtTemplate/gi, _newCtrl);
				var editor1 = document.getElementById(_idCtrlEditor);
				// pasting the specified HTML into a range within a editor document 
				editor1.setHTML(_cthh);
				$("#" + _idCtrlEditor).find('iframe').css({ 'height': '120px' });
				$("#[id*=UpdateProgress1]").css({ 'display': 'none' });
			}, 500);
		} catch (e) { $("#[id*=UpdateProgress1]").css({ 'display': 'none' }); }
	}

	function SetValueForm() {
		var strValue = "";
		$(".BoxField table[@id^=tb1] tbody tr").each(function (e) {
			try {
				var _thanhPhan = $(this).find(".ThanhPhan").val().trim();
				var _soCAS = $(this).find(".SoCAS").val().trim();
				//var _ctHH = $(this).find(".CTHH").val().trim();
				var _ctHH = "";
				var _refCtrlValue = '<%= txtTemplate.ClientID%>'.replace(/txtTemplate/gi, $(this).attr("data-ctrlName"));
					_ctHH = $("#" + _refCtrlValue).find('iframe').contents().find('body').html().replace(/<br>/gi, "");
					var _hamluong = $(this).find(".HamLuong").val().trim();
					if (_thanhPhan + _soCAS + _ctHH + _hamluong != "")
						strValue += (_thanhPhan + "@" + _soCAS + "@" + _ctHH + "@" + _hamluong) + "$";
				} catch (e) {
				}
			});
			if (strValue.trim() == "") {
				$('#lstErrorContent li').remove();
				//show new list bug
				$("#lstErrorContent").append('<li><%=hidErrorSection02.Value %></li>');
			$('html, body').animate({ scrollTop: $(".Error").height() }, 800);
			return false;
		}
		$("#hidValue").val(strValue);

		return true;
	}
</script>
<asp:UpdatePanel ID="uplCauhoi2" runat="server">
	<ContentTemplate>
		<div style="clear: both; height: 20px"></div>
		<div class="BoxField">
			<div class="DivRow">
				<div class="HeadTitle">
					<h3>
						<asp:Label ID="lblHeaderNhandang" runat="server" Text="PHẦN II. THÔNG TIN VỀ THÀNH PHẦN NGUY HIỂM" /></h3>
				</div>
			</div>
			<div class="DivRequired">
				<span class="fieldRequired">&nbsp;</span>
				<asp:Literal
					ID="ltrRequired" Text="Trường yêu cầu nhập dữ liệu" runat="server"></asp:Literal>
			</div>
			<%--<div class="Error">
				<asp:ValidationSummary ID="ValidationSummary1" runat="server" ForeColor="#FF3300" />
			</div>--%>
			<div class="Error">
				<div id="divError">
					<ul id="lstErrorContent">
					</ul>
				</div>
			</div>
			<div id="divTemplate" style="display: none">
				<ce:editor id="txtTemplate" runat="server" height="100%" width="100%" configurationpath="~/CuteSoft_Client/CuteEditor/Configuration/AutoConfigure/Simple.config"
					editorwysiwygmodecss="~/example.css">
					<TextAreaStyle BackColor="White" BorderColor="#DDDDDD" BorderStyle="Solid" BorderWidth="1px"
						CssClass="CuteEditorFrame" Height="100%" Width="100%" />
				</ce:editor>
			</div>

			<div class="DivRow">
				<div style="clear: left; height: 10px">
				</div>
				<div style="width: 100%;" class="DivTextBox">
					<table id="tb1" cellpadding="0" width="99%" cellspacing="0" border="1" class="GridBorder">
						<thead>
							<tr align="center" style="height: 26px;">
								<td width='5%' class='text_list_links' align='center'></td>
								<td width='20%' class='text_list_links' align='center'>
									<asp:Label ID="lblHeaderThanhphan02" runat="server" Text="Tên thành phần nguy hiểm" />
								</td>
								<td width='20%' class='text_list_links' align='center'>
									<asp:Label ID="lblHeaderSoCAS02" runat="server" Text="Số CAS" />
								</td>
								<td width='40%' class='text_list_links' align='center'>
									<asp:Label ID="lblHeaderCTHH02" runat="server" Text="Công thức hóa học" />
								</td>
								<td width='15%' class='text_list_links' align='center'>
									<asp:Label ID="lblHeaderPhantram02" runat="server" Text="Hàm lượng (% theo trọng lượng)" />
								</td>
							</tr>
						</thead>
					</table>
					<div style="clear: left; height: 10px">
					</div>
					<input id="btnAdd1" runat="server" type="button" class="btn" value=" Thêm " data-tbname="tb1" />
				</div>
			</div>
			<div style="clear: both; padding-top: 10px;">
			</div>
			<div class="DivRow">
				<div class="DivLabel">
					&nbsp;&nbsp;&nbsp;
				</div>
				<div class="DivTextBox">
					<div style="float: left">
						<asp:Button ID="btnSave" runat="server" Text=" Save - Next " CssClass="btn" CausesValidation="false" OnClientClick="return SetValueForm();" />
						&nbsp;<asp:Button ID="btnPrevious" runat="server" CausesValidation="false" CssClass="btn"
							Text="Previous" />
					</div>
					<div style="float: right; text-align: right">
					</div>
				</div>
			</div>
			<asp:HiddenField ID="hidMSDSID" Value="0" runat="server" />
			<asp:HiddenField ID="hidID" Value="0" runat="server" />
			<asp:HiddenField ID="hidMode" Value="0" runat="server" />
			<!-- 0: Create; 1: Edit-->

			<asp:HiddenField ID="hidDel" Value=" Xóa " runat="server" ClientIDMode="Static" />
			<asp:HiddenField ID="hidValue" Value="" runat="server" ClientIDMode="Static" />

			<asp:HiddenField ID="hidErrorSection02" Value="Vui lòng nhập ít nhất một dòng dữ liệu !" runat="server" ClientIDMode="Static" />
		</div>
	</ContentTemplate>
</asp:UpdatePanel>
